<?php


require_once(dirname(__FILE__).'/../../common/log.php');
require_once(dirname(__FILE__).'/../../common/defines.php');
require_once(dirname(__FILE__).'/../../common/return.php');
require_once(dirname(__FILE__).'/../../utils/HttpUtils.php');


$body  = file_get_contents('php://input');   
logd("recv: ".$body);

$data  = json_decode($body, true);
if ((!isset($data['userId'])) || (!is_int($data['userId'])))
{
    loge("params error !");

    failure(ERR_PARAM);
}

$info['userId']  = $data['userId'];
$info['nonce']   = time();
//排序
ksort($info);
//
$arr  = [];
foreach ($info as $k => $v)
{
    $arr[]  = "$k=$v";
}
$src  = join("&",$arr);
$enc  = md5($src.'e04d5114a0c56836e1acf734f200d422');

$head['version']  = 1;
$head['appId']    = 'zuprx235';
$head['sign']     = $enc;

$ret  = HttpUtils::send_post_request('https://kmsg.cdks.net/api/getUserToken', $head, $info);
logd($ret['data']);

echo $ret['data'];
